<template>
<div>
  <center>
  <h1>申请收房贷</h1>
  </center>
  <el-form ref="form" :inline="true" :model="form"  label-width="80px">
    <el-form-item label="收房合同编号" prop="sfContractNo">
      <el-input v-model="form.sfContractNo" placeholder="请输入收房合同编号"  disabled="true"/>
    </el-form-item>
    <el-form-item  >
      <el-button type="primary" @click="gethouse">收房合同查询</el-button>
    </el-form-item>
    <br>
    <el-form-item label="房产信息" prop="houseName">
      <el-input v-model="form.houseName" placeholder="请输入房产信息"  disabled="true"/>
    </el-form-item><br>
    <el-form-item label="业主姓名" prop="ownerName">
      <el-input v-model="form.ownerName" placeholder="请输入业主姓名"  disabled="true"/>
    </el-form-item>
    <el-form-item label="业主手机号" prop="ownerName">
      <el-input v-model="form.ownerMobile" placeholder="请输入业主手机号" disabled="true" />
    </el-form-item><br>
    <el-form-item label="业主身份证" prop="ownerIdCard">
      <el-input v-model="form.ownerIdCard" placeholder="请输入业主身份证"  disabled="true"/>
    </el-form-item>
    <el-form-item label="银行卡号" prop="bankCard">
      <el-input v-model="form.bankCard" placeholder="请输入银行卡号"  disabled="true"/>
    </el-form-item><br>
    <el-form-item label="银行名称" prop="bankName">
      <el-input v-model="form.bankName" placeholder="请输入银行名称"  disabled="true"/>
    </el-form-item>
    <el-form-item label="开户行" prop="bankOpen">
      <el-input v-model="form.bankOpen" placeholder="请输入开户行"  disabled="true"/>
    </el-form-item>
    <hr>
    <el-form-item label="金融产品选择">
      <el-select v-model="form.productId" placeholder="请选择"  @change="getproduct">
        <el-option  v-for="item in product"
                    :key="item.id"
                    :value="item.id"
                    :label="item.jrProductName" ></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="年利率" prop="rate">
      <el-input v-model="form.rate"   placeholder="请输入年利率"  >
        <template slot="append">%</template>
      </el-input>
    </el-form-item><br>
    <el-form-item label="借款期限" prop="periods">
      <el-input v-model="form.periods" placeholder="请输入借款期限" disabled="true" />
    </el-form-item>
    <el-form-item label="年一次性服务费率" prop="serviceFee">
      <el-input v-model="form.serviceFee" placeholder="请输入年一次性服务费率"  >
        <template slot="append">%</template>
      </el-input>
    </el-form-item><br>
    <el-form-item label="借款金额" prop="balance">
      <el-input v-model="form.balance" placeholder="请输入借款金额"  />
    </el-form-item>
    <el-form-item label="授信额度" prop="creditLine">
      <el-input v-model="form.creditLine" placeholder="请输入授信额度" disabled="true" >
        <template slot="append">%</template>
      </el-input>
    </el-form-item><br>
    <el-form-item  >
      <el-button type="primary" @click="sum">分期计算详情</el-button>
    </el-form-item>
  </el-form>
  <el-table
    :data="tableData2"
    style="width: 100%" :hidden=loan>
    <el-table-column
      prop="no"
      label="序号">
    </el-table-column>
    <el-table-column
      prop="realEstateInfo"
      label="房产信息">
    </el-table-column>
    <el-table-column
      prop="roomCode"
      label="房源编号">
    </el-table-column>
    <el-table-column
      prop="monthRepaymentAmount"
      label="账期还款金额">
      <template v-slot="code">
        {{code.row.monthRepaymentAmount+'元'}}
      </template>
    </el-table-column>
    <el-table-column
      prop="monthRateAmount"
      label="账期利息">
      <template v-slot="code">
        {{code.row.monthRateAmount+'元'}}
      </template>
    </el-table-column>
    <el-table-column
      prop="starLoanday"
      label="借款期限">
      <template v-slot="code">
        {{code.row.starLoanday+' 至 '+code.row.endLoanday}}
      </template>
    </el-table-column>
  </el-table>
  <el-form :inline="true" :model="loans" class="demo-form-inline" label-width="150px" :hidden=loan>
    <el-form-item label="应付租约合计">
      <el-input v-model="form.payAbleCount" disabled=""></el-input>
    </el-form-item>
    <el-form-item label="还款总额合计">
      <el-input v-model="form.rePaymentCount" disabled=""></el-input>
    </el-form-item>
    <br>
    <el-form-item label="服务费">
      <el-input v-model="form.serCharge" disabled=""></el-input>
    </el-form-item>
    <el-form-item label="收房贷利息合计">
      <el-input v-model="form.interestCount" disabled=""></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="estate">
      <el-input type="textarea" v-model="estate"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm">提交申请</el-button>
    </el-form-item>
  </el-form>
  <el-dialog title="收房合同查询" :visible.sync="dialogFormVisible">
    <el-form :model="houselist"  :inline="true">
      <el-form-item label="小区名称" :label-width="formLabelWidth">
        <el-input v-model="houselist.premiseName" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="业主姓名" :label-width="formLabelWidth">
        <el-input v-model="houselist.ownerName" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item  >
        <el-button type="primary" @click="gethouselist">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData">
      <el-table-column property="ownerName" label="业主姓名" width="150"></el-table-column>
      <el-table-column property="houseName" label="房产信息" width="200"></el-table-column>
      <el-table-column property="conSignTime" label="签约日期"></el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        width="100">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small">选中</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="houselist.pageNum"
      :limit.sync="houselist.pageSize"
      @pagination="gethouselist"
    />
  </el-dialog>
</div>
</template>

<script>
import {listhouse,listproduct,listSfLoan,productByid,save} from "@/api/message/installment";

export default {
  name: "house",
  data(){
    return{
      dialogFormVisible2:false,
      estate:'',
      loan:true,
      form:{
        creditLine:'',
        periods:''
      },
      total:0,
      tableData2:[],
      product:[],
      houselist:{
        pageSize:5,
        pageNum:1,
        premiseName:'',
        ownerName:''
      },
      dialogFormVisible:false,
      formLabelWidth: '120px'
    }
  },
  methods:{
    submitForm(){
      save(this.form).then(res=>{
        if (res.data.code===200){
          this.$message.success("添加成功")
          this.$router.push("/message/index")
        }else {
          this.$message.error("添加失败")
        }
      })
    },
    sum(){
      console.log(this.form)
      listSfLoan(this.form).then(res=>{
          console.log(res)
          this.loan=false;
          this.tableData2=res.dataList.sfLoan;
          this.form.payAbleCount=res.dataList.payAbleCount;
          this.form.rePaymentCount=res.dataList.rePaymentCount;
          this.form.serCharge=res.dataList.serCharge;
          this.form.interestCount=res.dataList.interestCount;

      })
    },
    getproduct(){
      productByid(this.form.productId).then(res=>{
        this.form.creditLine="";
        this.form.periods="";
        this.form.creditLine=res.creditLine;
        this.form.periods=res.instalmentPeriod;
        console.log(this.form)
      })
    },
    handleClick(row){
      this.form=row;
      this.form.startDate =row.leaseStartTime
      this.form.endDate =row.leaseEndTime
      this.dialogFormVisible=false;
    },
    gethouselist(){
      listhouse(this.houselist).then(res =>{
        this.tableData = res.list;
        this.total = res.total;
      })
    },
    gethouse(){
      this.dialogFormVisible=true;
     },
    getlistproduct(){
      listproduct().then(res=>{
        this.product=res;
        console.log(this.product)
      })
    }
  },
  created() {
    this.gethouselist();
    this.getlistproduct();
  }
}
</script>

<style scoped>

</style>
